import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:rive/rive.dart';

class LotteryAnimationView extends StatefulWidget {
  const LotteryAnimationView({super.key});

  @override
  State<LotteryAnimationView> createState() => _LotteryAnimationViewState();
}

class _LotteryAnimationViewState extends State<LotteryAnimationView> {
  final player = AudioPlayer();

  @override
  void initState() {
    super.initState();
    // 播放摇奖音效
    player.play(AssetSource('sounds/draw_sound.mp3'));
  }
  
  @override
  void dispose() {
    player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text(
          '开奖中...',
          style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold, color: Colors.cyanAccent),
        ),
        const SizedBox(height: 40),
        SizedBox(
          width: MediaQuery.of(context).size.width * 0.9,
          height: MediaQuery.of(context).size.width * 0.9,
          child: const RiveAnimation.asset(
            // !重要: 请确保你有名为 lottery_machine.riv 的 Rive 文件在 assets/animations/ 目录下
            'assets/animations/lottery_machine.riv',
            fit: BoxFit.contain,
          ),
        ),
      ],
    );
  }
}